var softwareHelper = {
	getNewVersion(software) {
		if (software.versions.length == 0) {
			return new_version = '0.0.0';
		} else {
			let versions = software.versions;
			let length = software.versions.length;
			//logger.debug('versions',versions);

			for (let i = 0; i < length; i++) {
				for (let j = 0; j < i; j++) {
					//logger.debug('versions[j].version,versions[j + 1].version', versions[j].version, versions[j + 1].version, toNum(versions[j].version) < toNum(versions[j + 1].version));
					if (softwareHelper.toNum(versions[j].version) < softwareHelper.toNum(versions[j + 1].version)) {
						i = 0;
						let temp = versions[j + 1];
						versions[j + 1] = versions[j];
						versions[j] = temp;
					}
				}
			}
			software.versions = versions[0];
			return new_version = software.versions;
		}
	},

	toNum(a) {
		var a = a.toString();
		//也可以这样写 var c=a.split(/\./);
		var c = a.split('.');
		var num_place = ["", "0", "00", "000", "0000"],
			r = num_place.reverse();
		//logger.debug('r, c',r, c);
		for (var i = 0; i < c.length; i++) {
			var len = c[i].length;
			c[i] = r[len] + c[i];
		}
		var res = c.join('');
		//logger.debug('res', res);
		return res;
	},
}

module.exports = softwareHelper;